package com.itheima.skyserver.mapper;

import com.github.pagehelper.Page;
import com.itheima.skyserver.pojo.domain.Category;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CategoryMapper {
    Page<Category> page(String name, Integer type);

    @Update("update category set status = #{status}, update_time = now() where id = #{id};")
    void setStatus(Integer status, Long id);

    @Insert("insert into category (sort, name, type, create_time, update_time, status, update_user, create_user) values (#{sort}, #{name}, #{type}, now(), now(), 1, #{updateUser}, #{createUser});")
    void insertCategory(Category category);

    @Delete("delete from category where id = #{id};")
    void deleteCategoryById(Integer id);

    @Select("select * from category where type = #{type};")
    List<Category> list(Integer type);

    @Update("update category set name = #{name}, sort = #{sort}, update_time = now(), update_user = #{updateUser} where id = #{id};")
    void updateCategory(Category category);
}
